package 微软笔试.task1;

public class Solution {
    public int solution(int N) {
        // write your code in Java SE 8

        int left = 0;
        int right = N;
        while(left<=right){
            int mid = left+(right-left)/2;
            long val = mid*(mid+1)/2;
            if(val==N){
                return mid;
            }else if(val>N){
                right = mid-1;
            }else{
                left = mid+1;
            }

        }
        return right;
    }
}
